package cn.tedu.school.portal.vo;

import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)   //这个注解可以让这个类用这种写法 return new R().setState(4).setMessage("注册失败,手机号已经被注册");
public class R<T> {
    private Integer state;
    private String message;
    private T data;


    public static cn.tedu.school.portal.vo.R ok() {
        return new cn.tedu.school.portal.vo.R().setState(State.OK);
    }

    public static cn.tedu.school.portal.vo.R failure(Integer state, String message) {
        return new cn.tedu.school.portal.vo.R().setState(state).setMessage(message);
    }

    public static cn.tedu.school.portal.vo.R failure(Integer state, Throwable e) {
        return failure(state, e.getMessage());
    }

    public static<T> cn.tedu.school.portal.vo.R ok(T data){
        return new cn.tedu.school.portal.vo.R<T>().setState(State.OK).setData(data);
    }

    /**
     * 静态的内部接口
     */
    public static interface State{
        int OK = 2000;
        int ERR_PARAMETER_VALIDATION = 4000;
        int ERR_STUDENT_ID_DUPLICATE = 4001;
        int ERR_STUDENT_DO_NOT_EXIST = 4002;
        int ERR_PASSWORD_NOT_MATCH =4003;
        int ERR_PASSWORD_DUPLICATE =4004;
        int ERR_ACCESS_DENIED = 4005;
        int ERR_INSERT = 4009;
        int ERR_UNKNOWN = 9999;

    }


}
